/**
 * Copyright (C) 2016 Hyphenate Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *     http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.nf.health.app.mydoctor.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.hyphenate.chat.EMGroup;
import com.nf.health.app.R;

import java.util.List;

public class GroupNewAdapter extends BaseAdapter {

	private LayoutInflater inflater;
	private Context context;
	private List<EMGroup> groups;
	public GroupNewAdapter(Context context, List<EMGroup> groups) {
		this.inflater = LayoutInflater.from(context);
		this.context = context;
		this.groups = groups;
	}

	@Override
	public int getCount() {

		return groups == null ? 0 :groups.size();
	}

	@Override
	public Object getItem(int position) {
		return groups.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	public void setMyDataChanged( List<EMGroup> groups){
		this.	groups = groups;
		notifyDataSetChanged();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.em_row_add_group, null);
			holder.name = (TextView) convertView.findViewById(R.id.name);
			holder.avatarImg = (ImageView) convertView.findViewById(R.id.avatar);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag();
		}
		EMGroup model = groups.get(position);
		holder.name.setText(model.getGroupName() == null ? "张三" : model.getGroupName());
		holder.avatarImg.setImageResource(R.drawable.em_create_group);
		return convertView;
	}
	class ViewHolder {
		TextView name;
		ImageView avatarImg;
	}

}
